package com.example.demo1.util;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

/**
 * 用于封装后台返回结果,规定一个数据结构
 */
@ApiModel("用于封装后台返回结果,规定一个数据结构")
@Data
public class ResultUtil {
    /**
     * success为0,表示操作成功
     * success为其他代码,表示操作失败
     */
    @ApiModelProperty("success为0,表示操作成功;success为其他代码,表示操作失败")
    private Integer success = 0;
    @ApiModelProperty("message信息说明")
    private String message;
    @ApiModelProperty("data后端返回的数据")
    private Object data;

    public static ResultUtil success() {
        ResultUtil resultUtil = new ResultUtil();
        return resultUtil;
    }


    public static ResultUtil success(Object data) {
        ResultUtil resultUtil = new ResultUtil();
        resultUtil.setData(data);
        return resultUtil;
    }

    public static ResultUtil success(String message, Object data) {
        ResultUtil resultUtil = new ResultUtil();
        resultUtil.setMessage(message);
        resultUtil.setData(data);
        return resultUtil;
    }

    public static ResultUtil fail(Integer code, String message) {
        ResultUtil resultUtil = new ResultUtil();
        resultUtil.setSuccess(code);
        resultUtil.setMessage(message);
        return resultUtil;
    }
}
